﻿using AutoMapper;
using Common;
using Common.Property;
using Domain.Sys;
using DTO.DTO.Sys.Module;
using IServices.Sys;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Web.Filter;
using Web.Framework;

namespace Web.Controllers
{
    [NoPermission]
    public class HomeController : BaseController
    {
        private readonly IRoleService _rService;

        public HomeController(IHttpContextAccessor httpContextAccessor, IRoleService rService, IMapper mapper):base(httpContextAccessor, mapper)
        {
            _rService = rService;
        }

        public async Task<IActionResult> Index()
        {
            var user = _HttpContext.User;
            ViewBag.SurName = UserInfo.SurName;
            var list = new List<ModuleFullDTO>();
            await Task.Run(() => { list = _rService.GetRecursionModuleList("", E_ModuleType.Menu.ToString(), E_Status.Enabled.ToString(), ""); });
            if (UserInfo.IsAdmin != 1)
            {
                var idList = await _rService.GetUserModule(UserInfo.UserId);
                list = list.Where(o => idList.Contains(o.Id)).ToList();
            }
            ViewBag.Menu = list;
            return View();
        }

        public async Task<IActionResult> Main()
        {
            return View();
        }

        [NoLogin]
        public async Task<IActionResult> Error()
        {
            return View();
        }
    }
}